#include "doneflag.h"

static int doneflag = 0;
static pthread_mutex_t donelock = PTHREAD_MUTEX_INITIALIZER;

/* getdone函数用于返回同步标志的值 */
int getdone(int *flag) {
    int error;
    if (error = pthread_mutex_lock(&donelock))
        return error;
    *flag = doneflag;

    return pthread_mutex_unlock(&donelock);
}

/* setdone函数用于将同步标志的值修改为1 */
int setdone(void) {
    int error;
    if (error = pthread_mutex_lock(&donelock))
        return error;
    doneflag = 1;

    return pthread_mutex_unlock(&donelock);
}
